<template>
    <button class="hm-button" :class="[`hm-button-${type}`, {
      'is-plain': plain,
      'is-round': round, // 控制圆角
      'is-circle': circle, // 圆型按钮
      'is-disabled': disabled // 按钮是否禁用
    }]"
    :disabled="disabled"
    @click="handleClick"
    >
      <i v-show="icon" :class="icon"></i>
      <span v-if="$slots.default"><slot></slot></span>
    </button>
</template>

<script>
export default {
  name: 'HmButton',
  props: {
    type: {
      type: String, // 数据类型-字符串
      default: 'default'
    },
    plain: {
      type: Boolean,
      default: false
    },
    round: {
      // 圆角属性
      type: Boolean,
      default: false
    },
    circle: {
      // 圆型按钮
      type: Boolean,
      default: false
    },
    icon: {
      // 图标属性
      type: String,
      default: ''
    },
    disabled: {
      // 按钮是否禁用
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleClick (e) {
      // 派发事件
      this.$emit('click', e)
    }
  }
}
</script>

<style lang="scss" scoped>
.hm-button {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: #fff;
  border: 1px solid #dcdfe6;
  color: #606266;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
// 禁止元素的文字被选中
-moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
&:hover,
&:focus {
   color: #409eff;
   border-color: #c6e2ff;
   background-color: #ecf5ff;
 }
}
.hm-button-primary {
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;
  &:hover,
  &:focus {
    background: #66b1ff;
    background-color: #66b1ff;
    color: #fff;
  }
}
.hm-button-success {
  color: #fff;
  background-color: #67c23a;
  border-color: #67c23a;
  &:hover,
  &:focus {
    background: #85ce61;
    background-color: #85ce61;
    color: #fff;
  }
}
.hm-button-info {
  color: #fff;
  background-color: #909399;
  border-color: #909399;
  &:hover,
  &:focus {
    background: #a6a9ad;
    background-color: #a6a9ad;
    color: #fff;
  }
}
.hm-button-warning {
  color: #fff;
  background-color: #e6a23c;
  border-color: #e6a23c;
  &:hover,
  &:focus {
    background: #ebb563;
    background-color: #ebb563;
    color: #fff;
  }
}
.hm-button-danger {
  color: #fff;
  background-color: #f56c6c;
  border-color: #f56c6c;
  &:hover,
  &:focus {
    background: #f78989;
    background-color: #f78989;
    color: #fff;
  }
}
//朴素样式
.hm-button.is-plain {
  &:hover,
  &:focus {
    background: #fff;
    border-color: #489eff;
    color: #409eff;
  }
}
.hm-button-primary.is-plain {
  color: #409eff;
  background: #ecf5ff;
  &:hover,
  &:focus {
    background: #409eff;
    border-color: #409eff;
    color: #fff;
  }
}
.hm-button-success.is-plain {
  color: #67c23a;
  background: #c2e7b0;
  &:hover,
  &:focus {
    background: #67c23a;
    border-color: #67c23a;
    color: #fff;
  }
}
.hm-button-info.is-plain {
  color: #909399;
  background: #d3d4d6;
  &:hover,
  &:focus {
    background: #909399;
    border-color: #909399;
    color: #fff;
  }
}
.hm-button-warning.is-plain {
  color: #e6a23c;
  background: #f5dab1;
  &:hover,
  &:focus {
    background: #e6a23c;
    border-color: #e6a23c;
    color: #fff;
  }
}
.hm-button-danger.is-plain {
  color: #f56c6c;
  background: #fbc4c4;
  &:hover,
  &:focus {
    background: #f56c6c;
    border-color: #f56c6c;
    color: #fff;
  }
}
// round属性
.hm-button.is-round {
  border-radius: 20px;
  padding: 12px 23px;
}
// circle属性
.hm-button.is-circle {
  border-radius: 50%;
  padding: 12px;
}
.hm-button [class*=hm-icon-]+span {
  margin-left: 5px;
}

/* 禁用 */
.hm-button.hm-button.is-disabled .mask {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: rgba(148, 146, 146, 0.39);
  left: 0;
  top: 0;
  box-shadow: 2px 2px 3px rgba(216, 213, 213, 0.3);
  border-radius: 4px;
  z-index: 100;
}

.hm-button.is-round .mask {
  border-radius: 20px;
}
.hm-button.is-circle .mask {
  border-radius: 50%;
}
.hm-button.is-disabled {
  cursor: no-drop;
}
</style>
